import { defineStore } from 'pinia';

const useAppStore = defineStore('app', {
	state: () => ({
		isSdkReady: false,
		isCalling: false,
		systemInfo: null,
		menuList: uni.getStorageSync('menuList') || [],
		toast: {
			title: '',
			duration: 2000
		}
	}),
	getters: {
		isSdkReady: state => state.isSdkReady,
		isCalling: state => state.isCalling,
		isIphoneX: state => state.systemInfo && state.systemInfo.model.indexOf('iPhone X') > -1,
		menuList: state => state.menuList,
	},
	actions: {
		setSdkReady(isReady) {
			this.isSdkReady = isReady;
		},
		setCalling(isCalling) {
			this.isCalling = isCalling;
		},
		setSystemInfo(systemInfo) {
			this.systemInfo = systemInfo;
		},
		setMenuList(menuList) {
			this.menuList = menuList;
			uni.setStorageSync('menuList', menuList);
		},
		showToast(toast) {
			this.toast = toast;
			// 显示 toast 的逻辑
			uni.showToast({
				title: toast.title,
				duration: toast.duration || 2000
			});
		}
	},
});

export default useAppStore;